//被追答的问题的pk值
var beAnsweredQuestion = null;

//获得追问和追答
var getinfo = function(){

    $.ajax({
        type : "POST",
        url : WebSite.UnAdoptHandlingPage.questionAndAnswer,
        dateType : "json",
        data:{
            "pk_question":getUrlParam("pk_question")
        },
        success : function(result){
            if(result.success){
                var wantedPkList = result.resultData.list;
                for(var i = 0; i < wantedPkList.length; i++){
                    //每次循环把pk值覆盖，直到取到最后一个
                    beAnsweredQuestion = wantedPkList[i].pk_question_son;
                }
                var myTemplate = Handlebars.compile($("#handling-template").html());
                $("#handling-info").html(myTemplate(result));
            }else{
                alert(result.msg);
            }

        },
        error : function () {
            alert("问题的详细信息未获取到");
        }
    });

};

//改变时间格式
Handlebars.registerHelper("transdate", function(str, options) {
    return new Date(parseInt(str)).toLocaleString();
});


//追答
var submitAnswer = function(){
    var submitFormOptions = {
        url          : WebSite.ReplayerHandlingPage.continueAnswer,
        type         : "post",
        dataType     : "json",
        data         : {
            "pk_sool_question" : beAnsweredQuestion
        },
        beforeSubmit : function(){
            if($("#contentEditor").text() == ""){
                alert("提交的答案不能为空");
                return false;
            };
        },
        success : function(result){
            if(result.success){
                var myTemplate = Handlebars.compile($("#addAnswerTemplate").html());
                $("#storeAddAnswer").append(myTemplate(result));
                $("#submitAnswer").hide();
                location.reload();
            }else{
                alert(result.msg);
            }

        },
        error : function(){
            alert("提交答案未成功");
        }
    };
    $("#continueAnswer").ajaxForm(submitFormOptions);
};

//弹出附件上传
function getUpload(){
    $(".uploadDisplay").addClass("uploadDisplay-block");
};
